const app = getApp();
Component({
  /**
   * 页面数据
   */
  data: {
    list: {},
  },

  /**
   * 各种方法
   */
  methods: {
    onItemTap: function(e){
      app.idx = e.currentTarget.dataset.index;
      wx.navigateTo({
        url: '../view-page/view-page',
      })
      console.log(app.list);
    },

    onPullDownRefresh: function(){
      // 上拉刷新
      var that = this;
      wx.request({ 
        url: 'http://39.97.114.188:8081/queryCommentList',
        method:'GET',
        success:function(res){
          // console.log("回调函数:"+res.data)
          var resData = res.data;
          if(resData != null){
              that.setData({
                list: resData.reverse(),
              })
              app.list = that.data.list;
              console.log(that.data.list);
          }else{
              wx.showToast({
                  title: '网络错误',
                  duration:2000
              })
          }
        },
        fail:function(res){
          wx.showToast({
            title: '网络错误',
            duration: '2000'
          })
        }
      })
      wx.stopPullDownRefresh({
        success: (res) => {
          wx.showToast({
            title: '刷新成功',
          })
        },
      })
  },
},

  /**
   * ready 生命周期函数
   */
  ready: function(){
    var that = this;
    wx.request({
      url: 'http://39.97.114.188:8081/queryCommentList',
      method:'GET',
      success:function(res){
        // console.log("回调函数:"+res.data)
        var resData = res.data;
        if(resData != null){
            that.setData({
              list: resData.reverse(),
            })
            app.list = that.data.list;
            console.log(that.data.list);
        }else{
            wx.showToast({
                title: '网络错误',
                duration:2000
            })
        }
      }
    })
  },

  pageLifetimes: {
    show() {
      if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 0
        })
      }
    }
  }

})